#include <iostream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "AbstractGraph.h"
#include "Graph.h"
#include "BipartiteGraph.h"
#include "Tree.h"
#include "SmallCover.h"
#include "Algorithms.h"
#include "Minisat.h"

using namespace std;

void displayVector(vector<int> v) {
  vector<int>::iterator it;
  cout << "Couverture par sommets : ";
  for (it = v.begin(); it != v.end(); ++it) {
    cout << *it << "  ";
  }
  cout << endl;
}

void displayVectorMinisat(vector<int> v) {
  vector<int>::iterator it;
  cout << "Couverture par sommets : ";
  for (it = v.begin(); it != v.end(); ++it) {
    cout << *it-1 << "  ";
  }
  cout << endl;
}

int main(int argc, char *argv[])
{
  if (argc < 2)
    { 
      cout<<"Algorhitmes"<<endl;
      cout<<"Usage: "<<argv[0]<<" <Algo> <Fichier> "<<endl;
      cout<<"Algo : glouton | twoApprocheGraphe | twoApprocheVoisinage | optTree |optimalBiparti | parametric parametre-k |Minisat <size-Cover>"<<endl;
      exit (1) ;
    }

  if (strcmp(argv[1],"glouton")==0){
    AbstractGraph g;
    Algorithms a;
    g.readFile(argv[2]);
    cout<< g.toString()<<endl;
    vector<int> vect = a.glouton(g);
    displayVector(vect);
  }
  
  else if(strcmp(argv[1],"twoApprocheGraphe")==0){
    AbstractGraph g;
    Tree t;
    Algorithms a;
    g.readFile(argv[2]);
    vector<int> vect = a.twoApprocheGraphe(&g,&t,0);
    displayVector(vect);
  }

   else if(strcmp(argv[1],"twoApprocheVoisinage")==0){
    AbstractGraph g;
    Algorithms a;
    g.readFile(argv[2]);
    cout<< g.toString()<<endl;
    vector<int> vect = a.twoApprocheVoisinage(g);
    displayVector(vect);
  }

   else if(strcmp(argv[1],"optTree")==0){
    Tree t;
    Algorithms a;
    t.readFile(argv[2]); 
    cout<<t.toString()<<endl;
    vector<int> vect = a.optTree(t);
    displayVector(vect);
   } 
  
   else if(strcmp(argv[1],"optimalBipartite")==0){ 
     BipartiteGraph g;
     Algorithms a;
     g.readFile(argv[2]);
     vector<int> vect = a.optimalBipartite(g);
     displayVector(vect);
   }

   else if(strcmp(argv[1],"parametric")==0){ 
     AbstractGraph g; 
     Algorithms a;
     g.readFile(argv[3]);
     vector<int>  * v = a.parametricAlgorithm(g,atoi(argv[2]));
     if(v)
       displayVector(*v);
     else
       cout << "Failed to find a "<<argv[2] << "-cover" << endl; 
   }

   else if(strcmp(argv[1],"Minisat")==0){ 
     AbstractGraph g;
     g.readFile(argv[3]);
     Minisat m(&g, atoi(argv[2]));
     m.vcProblemToSat();
     vector<int> vect = m.satProblemToVc();
     displayVectorMinisat(vect);
   }
  return 0;
}

